#include<bits/stdc++.h>
using namespace std;
#define int long long

int fun(string s, string t) {
	vector<vector<int>> f(s.size() + 1, vector<int>(t.size() + 1));
	for (int i = 1; i <= s.size(); i++) {
		for (int j = 1; j <= t.size(); j++) {
			if (s[i - 1] == t[j - 1]) {
				f[i][j] = f[i - 1][j - 1] + 1;
			} else {
				f[i][j] = max(f[i - 1][j], f[i][j - 1]);
			}
		}
	}
	return f[s.size()][t.size()];
}

signed main() {
	for (int ii = 1; ii <= 3; ii++) {
		random_device sd;
		mt19937 mt(sd());
		uniform_int_distribution<int> disNM(1, 10);
		uniform_int_distribution<char> disCh('a', 'z');

		freopen((to_string(ii) + ".in").c_str(), "w", stdout);

		int n = disNM(mt);
		int m = disNM(mt);

		string s, t;
		while (n--) {
			s += disCh(mt);
		}
		cout << s << endl;

		while (m--) {
			t += disCh(mt);
		}
		cout << t << endl;
		fclose(stdout);

		freopen((to_string(ii) + ".out").c_str(), "w", stdout);
		cout << fun(s, t) << endl;
		fclose(stdout);
	}
	for (int ii = 4; ii <= 6; ii++) {
		random_device sd;
		mt19937 mt(sd());
		uniform_int_distribution<int> disNM(1, 200);
		uniform_int_distribution<char> disCh('a', 'z');

		freopen((to_string(ii) + ".in").c_str(), "w", stdout);

		int n = disNM(mt);
		int m = disNM(mt);

		string s, t;
		while (n--) {
			s += disCh(mt);
		}
		cout << s << endl;

		while (m--) {
			t += disCh(mt);
		}
		cout << t << endl;
		fclose(stdout);

		freopen((to_string(ii) + ".out").c_str(), "w", stdout);
		cout << fun(s, t) << endl;
		fclose(stdout);
	}
	for (int ii = 7; ii <= 10; ii++) {
		random_device sd;
		mt19937 mt(sd());
		uniform_int_distribution<int> disNM(1, 3000);
		uniform_int_distribution<char> disCh('a', 'z');

		freopen((to_string(ii) + ".in").c_str(), "w", stdout);

		int n = disNM(mt);
		int m = disNM(mt);

		string s, t;
		while (n--) {
			s += disCh(mt);
		}
		cout << s << endl;

		while (m--) {
			t += disCh(mt);
		}
		cout << t << endl;
		fclose(stdout);

		freopen((to_string(ii) + ".out").c_str(), "w", stdout);
		cout << fun(s, t) << endl;
		fclose(stdout);
	}
	return 0;
}
